//////////////////////////////////////////////////////////////////////////
//
// GAM203
// Light
// Light.cpp
// 
// Grant Johnson
// Qantm College
// 27/10/2010
//
//////////////////////////////////////////////////////////////////////////

#include "Light.h"

#include <d3dx9.h>
#include <d3dx9math.h>

Light::Light()
{
	ZeroMemory(&m_light, sizeof(m_light));
}

Light::~Light()
{
}
void Light::InitOmni()
{
	//Zero out the light structure
	ZeroMemory(&m_light, sizeof(m_light));
	m_light.Type = D3DLIGHT_POINT;

	SetRange(100.0f);
	SetAttenuation(0.5f);
}

void Light::InitSpot()
{
	//Zero out the light structure
	ZeroMemory(&m_light, sizeof(m_light));
	m_light.Type = D3DLIGHT_SPOT;

	//Init with some default settings
	SetPosition(3, 3, -2);
	SetCone(8.0f, 5.0f);
	SetDirection(D3DXVECTOR3(-3,-3,2));
	SetAmbient(1.0f, 1.0f, 1.0f);
	SetDiffuse(1.0f, 1.0f, 1.0f);
	SetSpecular(1.0f, 1.0f, 1.0f);
	SetRange(200);
	SetAttenuation(1.0f);
}

void Light::InitDirectional()
{
	ZeroMemory(&m_light, sizeof(m_light));
	m_light.Type = D3DLIGHT_DIRECTIONAL;
}

void Light::SetPosition(float a_xPos, float a_yPos, float a_zPos)
{
	//Set the position of the light
	m_light.Position.x = a_xPos;
	m_light.Position.y = a_yPos;
	m_light.Position.z = a_zPos;
}

void Light::SetPosition(const D3DVECTOR& a_pos)
{
	//Set the position of the light
	m_light.Position = a_pos;
}

void Light::SetDirection(const D3DVECTOR& a_dir)
{
	//Set the direction of the light
	m_light.Direction = a_dir;
}

void Light::SetAmbient(float a_red, float a_green, float a_blue)
{
	//Set the ambient colour of the light
	m_light.Ambient = D3DXCOLOR(a_red, a_green, a_blue, 1.0f);
}

void Light::SetDiffuse(float a_red, float a_green, float a_blue)
{
	//Set the diffuse colour of the light
	m_light.Diffuse = D3DXCOLOR(a_red, a_green, a_blue, 1.0f);
}

void Light::SetSpecular(float a_red, float a_green, float a_blue)
{
	//Set the specular colour of the light
	m_light.Specular = D3DXCOLOR(a_red, a_green, a_blue, 1.0f);
}

void Light::SetRange(float a_range)
{
	//Set the range of the light
	m_light.Range = a_range;
}

void Light::SetAttenuation(float a_attenuationFactor)
{
	//Set a linear attenuation
	m_light.Attenuation0 = 0.0f; 
	m_light.Attenuation1 = a_attenuationFactor;
	m_light.Attenuation2 = 0.0f;
}

void Light::SetCone(float a_theta, float a_phi)
{
	//Set the cone of the light

	//Set the inner cone
	m_light.Theta = a_theta;
	
	//Set the outer cone
	m_light.Phi = a_phi;

	m_light.Falloff = 1.0f;
}
